/**
 * Created by Administrator on 2017/5/25.
 */
"use strict";
//引入模块
const mongoose = require('mongoose');
const db = require('./db');

// Schema 结构
var BookSchema = new mongoose.Schema({
    bid      :{type:Number,index: true},//书籍ID
    bName      :{type:String,index: true},//书名
    imgurl    :{type : String,default:'/up/images/book/bookimg.png'},//书籍封面
    desc    : {type : String},//简介
    catId    : {type : Number,index: true},//类型ID
    cat    : {type : String,index: true},//类型
    subCateId    : {type : Number,index: true},//子类型ID
    subCateName    : {type : String,index: true},//子类型
    cid     : {type : Number,index: true},// 作者ID
    bAuth     : {type : String,index: true},//作者
    stateType      : {type : String,index: true,default:"T"},//连载状态
    signStatus      : {type : String,default:'E'},//E级签约签约类型
    isVip      : {type : Number,index: true,default:0},//是否vip
    startTime  : {type :Number , default:new Date().getTime()},//发布日期
    lastUpdateTime      : {type : Number,default: new Date().getTime()},//最后更新日期
    clickCnt: {type : Number,default:0},//点击数
    recomendCnt: {type : Number,index: true,default:0},//收藏数
    cnt: {type : Number,default:0},//书籍总字数
    month: {type : Number,index: true,default:0},//月票
    recomm: {type : Number,index: true,default:0},//推荐票
    reward: {type : Number,index: true,default:0},//打赏数
    bookType: {type : String,default:'male'},//男生
    // ariaFansNum: {type : Number},//粉丝数
    subscribe:{type:Number,default:0},//订阅
    bookCount: {type : Number,default:0},//书评数
    updateTime: {type : Number,default: new Date().getTime()},//更新日期
    updateTitle:{type:String,default:"暂无更新"},//更新章节
    lable: [{ lid: {type:Number}, "type": {type:String} }]//标签
});

BookSchema.statics.findFn = function(obj, callback) {
    return this.model('Book').find(obj, callback);
};
BookSchema.statics.findFnSmall = function(obj,obj2,obj3, callback) {
    return this.model('Book').find(obj,obj2, callback).sort(obj3);
};
BookSchema.statics.findFnLimit = function(obj,obj1,num1,callback) {
    return this.model('Book').find(obj).sort(obj1).limit(num1).exec(callback);
};
BookSchema.statics.findLimitSkip = function(obj,num1,num2,obj1,callback) {
    return this.model('Book').find(obj).limit(num1).skip(num2).sort(obj1).exec(callback);
};
BookSchema.statics.findSortOne = function(obj,obj1,callback) {
    return this.model('Book').findOne(obj).sort(obj1).exec(callback);
};
BookSchema.statics.findOneSmall = function(obj,obj2,obj3, callback) {
    return this.model('Book').findOne(obj,obj2, callback).sort(obj3);
};
BookSchema.statics.updateFn = function(obj,obj1,callback) {
    return this.model('Book').update(obj,obj1).exec(callback);
};
BookSchema.statics.removeFn = function(obj,callback) {
    return this.model('Book').remove(obj,callback);
};
BookSchema.statics.findConut = function(obj,callback) {
    return this.model('Book').find(obj).count().exec(callback);
};

var BookModel = db.model('Book', BookSchema);

module.exports=BookModel;